<?php
class GET_step_personal_info {
	private $connMgr;
	private $post_array;
	public function GET_step_personal_info($connMgr,$post_array) {
		$this->connMgr = $connMgr;
		$this->post_array = $post_array;
	}
	
	public function execute() {
		$connMng = $this->connMgr->getConn_step();
		$openid = $this->post_array ['OPENID'];
		$wximg = $this->post_array ['WXIMG'];
		$name = $this->post_array ['NAME'];

		
		$result_array = array();
		if ($openid != null&&$openid !='' ) {
			try {
				$mem_count = Step_count_DAO::getMemCount($connMng);
				$mem_id = $mem_count + 1;
				$step_mem_info_old = Step_count_DAO::getRecord($openid, $connMng);


				$datetime = date();

				if ($step_mem_info_old != null) {
					//已注册
					$result_array = array(
						RESULT => '2', ERR_MSG => '用户已注册！'
					);
					//无头像者设置默认头像
					if ( $wximg == ''||$wximg == null ){
						$wximg = 'http://tx.haiqq.com/qqtouxiang/uploads/2014-03-28/055125457.jpg';
					}
					//更新昵称与头像
					$step_mem_info_old->setImg($wximg);
					$step_mem_info_old->setName($name);
					Step_count_DAO::update($step_mem_info_old,$connMng);

					$step_mem_info = Step_count_DAO::getRecord($openid, $connMng);
					$result_array = array_merge($result_array, array("person_step" => $step_mem_info->toArray()));

					$step_mem_list = Step_count_DAO::getListByOrderDayLimit($connMng);
					$mem_array = array();
					foreach ($step_mem_list as $step_mem_record) {
						$mem_array [] = $step_mem_record->listToArray();
					}
					$result_array = array_merge_recursive($result_array, array("step_topten" => $mem_array));

					$step_mem_achieve_list = Step_count_DAO::getListByOrderAchieveTop($connMng);
					$achieve_array = array();
					foreach ($step_mem_achieve_list as $step_mem_achieve_list_record) {
						$achieve_array[] = $step_mem_achieve_list_record->listToArray();
					}

					$result_array = array_merge_recursive($result_array, array("achieve_topten" => $achieve_array));


				} else {
					$step_mem_info = new Step_count(array());
					$step_mem_info->setId($mem_id);
					$step_mem_info->setOpenid($openid);
					if ( $wximg == ''||$wximg == null ){
						$wximg = 'http://tx.haiqq.com/qqtouxiang/uploads/2014-03-28/055125457.jpg';
					}
					$step_mem_info->setImg($wximg);
					$step_mem_info->setName($name);
					$step_mem_info->setCreatedate($datetime);

					$step_mem_info->setPositionAll($mem_id);

					Step_count_DAO::insert($step_mem_info, $connMng);
					$result_array = array_merge($result_array, array(RESULT => '1', "person_step" => $step_mem_info->toArray()));

					$step_mem_list = Step_count_DAO::getListByOrderDayLimit($connMng);
					$mem_array = array();
					foreach ($step_mem_list as $step_mem_record) {
						$mem_array [] = $step_mem_record->listToArray();
					}

					$result_array = array_merge_recursive($result_array, array("step_topten" => $mem_array));

					$step_mem_achieve_list = Step_count_DAO::getListByOrderAchieveTop($connMng);
					$achieve_array = array();
					foreach ($step_mem_achieve_list as $step_mem_achieve_list_record) {
						$achieve_array[] = $step_mem_achieve_list_record->listToArray();
					}

					$result_array = array_merge_recursive($result_array, array("achieve_topten" => $achieve_array));

				}
			} catch (Exception $e) {
				throw $e;
			}
			return $result_array;
		}
	}
}

?>